package com.mobile.centaur.utils;

import android.os.Environment;

import java.io.File;
import java.util.HashMap;


/**
 * Created by 33290 on 2022/3/15.
 * 常量
 */

public class Common {

    private static Common instance;

    private Common() {
    }

    public static Common getInstance() {
        if (instance == null) {
            synchronized (Common.class) {
                if (instance == null) {
                    instance = new Common();
                }
            }
        }
        return instance;
    }

    public static final String KEY_TOKEN = "token_key";

    public static final String KET_UUID = "uuid_key";

    public static final String KEY_STATION = "station_key";

    public static final String KEY_CB = "cb_key";

    public String basePath =
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath();

    public void setBasePath(String path) {
        basePath = path;
        PATH_SAVE_CAMERA = basePath + File.separator + "camera" + File.separator;
        PATH_SAVE_VIDEO = basePath + File.separator;
        PATH_SAVE_UPLOAD = basePath + File.separator + "upload" + File.separator; //处理后准备上传的视频
    }

    public String getBasePath() {
        return basePath;
    }

    public String PATH_SAVE_DEVICE =
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + File.separator;

    public String PATH_SAVE_VIDEO = basePath + File.separator;

    public String PATH_SAVE_CAMERA = basePath + File.separator + "camera" + File.separator;

    public String PATH_SAVE_UPLOAD = basePath + File.separator + "upload" + File.separator; //处理后准备上传的视频

    public String getPATH_SAVE_DEVICE() {
        return PATH_SAVE_DEVICE;
    }

    public String getPATH_SAVE_VIDEO() {
        return PATH_SAVE_VIDEO;
    }

    public String getPATH_SAVE_CAMERA() {
        return PATH_SAVE_CAMERA;
    }

    public String getPATH_SAVE_UPLOAD() {
        return PATH_SAVE_UPLOAD;
    }

    private HashMap<String, String> commonMap1 = new HashMap<String, String>();
    private HashMap<String, Object> commonMap2 = new HashMap<String, Object>();

    /**
     * 保存
     */
    public void putString(String key, String value) {
        commonMap1.put(key, value);
    }

    /**
     * 获取
     */
    public String getString(String key) {
        return commonMap1.get(key);
    }

    public void put(String key, Object value) {
        commonMap2.put(key, value);
    }

    public <T> T get(String key) {
        Object obj = commonMap2.get(key);
        try {
            return (T) obj;
        } catch (Exception e) {
            return null;
        }
    }
}